Skip to content

demo: use pytest subtests in cuda.core system device loops to ensure full test coverage#2009

Draft
rwgk wants to merge 1 commit intoNVIDIA:mainfrom
rwgk:pytest_subtests_demo
Draft

demo: use pytest subtests in cuda.core system device loops to ensure full test coverage#2009
rwgk wants to merge 1 commit intoNVIDIA:mainfrom
rwgk:pytest_subtests_demo

Conversation

@rwgk
Copy link
Copy Markdown
Contributor

@rwgk rwgk commented May 1, 2026

Keep per-device skips and xfails from aborting the rest of the GPU system coverage.

Require pytest >= 9.0 in cuda.core test environments so the built-in subtests fixture is available.

To see how simple this change is, it's best to review with "Hide whitespace":

Screenshot 2026-05-01 at 15 51 57
git diff -b -w main -- cuda_core/tests/
@@ -341,8 +341,9 @@ def test_c2c_mode_enabled():


 @pytest.mark.skipif(helpers.IS_WSL or helpers.IS_WINDOWS, reason="Persistence mode not supported on WSL or Windows")
-def test_persistence_mode_enabled():
+def test_persistence_mode_enabled(subtests):
     for device in system.Device.get_all_devices():
+        with subtests.test(device_index=device.index):
             is_enabled = device.is_persistence_mode_enabled
             assert isinstance(is_enabled, bool)
             try:
@@ -615,14 +616,16 @@ def test_clock_event_reasons():
         assert all(isinstance(reason, system.ClocksEventReasons) for reason in reasons)


-def test_fan():
+def test_fan(subtests):
     for device in system.Device.get_all_devices():
         # The fan APIs are only supported on discrete devices with fans,
         # but when they are not available `device.num_fans` returns 0.
         if device.num_fans == 0:
+            with subtests.test(device_index=device.index):
                 pytest.skip("Device has no fans to test")

         for fan_idx in range(device.num_fans):
+            with subtests.test(device_index=device.index, fan_idx=fan_idx):
                 fan_info = device.get_fan(fan_idx)
                 assert isinstance(fan_info, _device.FanInfo)

@@ -655,8 +658,9 @@ def test_fan():
                     fan_info.set_default_speed()


-def test_cooler():
+def test_cooler(subtests):
     for device in system.Device.get_all_devices():
+        with subtests.test(device_index=device.index):
             # The cooler APIs are only supported on discrete devices with fans,
             # but when they are not available `device.num_fans` returns 0.
             if device.num_fans == 0:

Keep per-device skips and xfails from aborting the rest of the GPU system coverage. Require pytest 9 in cuda.core test environments so the built-in subtests fixture is available.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rwgk rwgk added this to the cuda.core next milestone May 1, 2026
@rwgk rwgk self-assigned this May 1, 2026
@rwgk rwgk added P1 Medium priority - Should do cuda.core Everything related to the cuda.core module labels May 1, 2026
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented May 1, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rwgk rwgk requested a review from mdboom May 1, 2026 22:50
Copy link
Copy Markdown
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good solution to the problem.

Do you plan to do this for all uses of get_all_devices? Ditto for the NVML tests in cuda_bindings.

Also, we should probably remove test_devices_are_the_same_architecture.

@rwgk
Copy link
Copy Markdown
Contributor Author

rwgk commented May 4, 2026

Looks like a good solution to the problem.

Do you plan to do this for all uses of get_all_devices? Ditto for the NVML tests in cuda_bindings.

This is mainly just my way to say "hey look this is new and useful."

But I'll leave this PR around in draft mode. After the dust has settled on the cuda-core v1.0.0 release, I'll look for opportunities to come back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants